package supplier

import (
	"io/ioutil"
	"net/http"
)

// 模拟请求第三方链接获取数据
type SupplierRepo interface {
	GET(url string, params string) ([]byte, error)
}

type HttpSupplierRepo struct {
	client *http.Client
}

func NewHttpSupplierRepo(client *http.Client) *HttpSupplierRepo {
	return &HttpSupplierRepo{
		client: client,
	}
}

func (h *HttpSupplierRepo) GET(url string, params string) ([]byte, error) {
	response, err := h.client.Get(url + params)
	if err != nil {
		return nil, err
	}
	defer response.Body.Close() // 确保关闭响应体
	// 读取响应体
	return ioutil.ReadAll(response.Body)

}
